using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace _395_2d
{
    public class Player : Ship
    {

        string Weapon;


        SoundEffect shoot_gun = SoundEffect.FromStream(TitleContainer.OpenStream(@"Content\shoot.wav"));
        SoundEffect player_hit = SoundEffect.FromStream(TitleContainer.OpenStream(@"Content\player_hit.wav"));


        public Player(SpriteManager sm, string t, string w, int h, Vector2 p, Vector2 s)
        {
            Texture = t;
            Weapon = w;
            Health = h;
            LastShot = new List<double>();
            LastShot.Add(0);

            bounds = new BoundingBox(p,s);
            SM = sm;
        }

        public void ModifyPosition(Vector2 deltaPos)
        {
            bounds.topLeft.X += deltaPos.X;
            bounds.topLeft.Y -= deltaPos.Y;
        }

        public override void Update(GameTime gt)
        {
            //Dummy Function
        }

        public override void shoot(GameTime gt)
        {
            Weapon w = (Weapon)Content.Weapons[Weapon];

            if (w.RateOfFire > 0 && gt.TotalGameTime.TotalSeconds - LastShot[0] > w.RateOfFire)
            {
                shoot_gun.Play();
                SM.AddProjectile(new Bullet(new Vector2(bounds.topLeft.X + bounds.size.X / 3 - 10f, bounds.topLeft.Y), new Vector2(0, -750), w.ProjectileDamage, w.ProjectileTexture));
                SM.AddProjectile(new Bullet(new Vector2(bounds.topLeft.X + bounds.size.X * 2 / 3 - 10f, bounds.topLeft.Y), new Vector2(0, -750), w.ProjectileDamage, w.ProjectileTexture));
                LastShot[0] = gt.TotalGameTime.TotalSeconds;
            }
        }

        public override void hit(Projectile p)
        {
            player_hit.Play();
            Health -= p.Damage;
        }
    }
}
